//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __CGZIPINPUTSTREAM_H__
#define __CGZIPINPUTSTREAM_H__

#include "_CGZipInputStream.h"
#include "zlib.h"

CarClass(CGZipInputStream)
{
public:
    CGZipInputStream() :
        m_pIis(NULL),
        m_pBuf(NULL),
        m_isEof(FALSE),
        bytesRead(0),
        m_pDict(NULL) {}

    ~CGZipInputStream();

    CARAPI constructor(
        /* [in] */ IInputStream * pStream);

    CARAPI constructor(
        /* [in] */ IInputStream * pStream,
        /* [in] */ Int32 windowBits);

    CARAPI constructor(
        /* [in] */ IInputStream * pStream,
        /* [in] */ Int32 windowBits,
        /* [in] */ const BufferOf<Byte> & dictionary);

    CARAPI Available(
        /* [out] */ Int32 * pBytes);

    CARAPI Close();

    CARAPI Mark(
        /* [in] */ Int32 readLimit);

    CARAPI IsMarkSupported(
        /* [out] */ Boolean * pSupported);

    CARAPI Read(
        /* [out] */ Byte * pValue);

    CARAPI ReadBuffer(
        /* [out] */ BufferOf<Byte> * pBuffer);

    CARAPI ReadBufferEx(
        /* [in] */ Int32 offset,
        /* [in] */ Int32 length,
        /* [out] */ BufferOf<Byte> * pBuffer);

    CARAPI Reset();

    CARAPI Skip(
        /* [in] */ Int32 length);

private:
    ECode fill();

    ECode InflateStream(
        Byte * pBuffer,
        Int32 bufferSize,
        Int32 * pCount);

private:
    IInputStream * m_pIis;
    BufferOf<Byte>* m_pBuf;
    z_stream m_stream;
    Boolean m_isEof;
    Int32 bytesRead;
    const BufferOf<Byte>* m_pDict;
};

#endif // __CGZIPINPUTSTREAM_H__
